#!/bin/sh

. $LKP_SRC/lib/reproduce-log.sh
. $LKP_SRC/lib/wait.sh

llvm_process()
{
  data_dir=/sys/kernel/debug/pgo

  if [[ ! -d ${data_dir} ]]; then
    echo "[ERROR] PGO data directory ${data_dir} does not exist."
    exit 1
  fi

  echo "[INFO] Start process profile."

  echo 1 > ${data_dir}/reset

  setup_wait
  wait_post_test

  temp_dir=$(mktemp -d)
  mkdir -p ${TMP_RESULT_ROOT}/results

  cp -a ${data_dir}/vmlinux.profraw ${temp_dir}/vmlinux.profraw

  llvm-profdata merge ${temp_dir}/vmlinux.profraw -o ${TMP_RESULT_ROOT}/results/vmlinux.profdata
  rm -rf ${temp_dir}

  echo "[INFO] Finished process profile."
}

llvm_process
